﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace Common
{
    public partial class GroupBox : UserControl
    {
        private float _borderWidth = 1.00f;

        public GroupBox()
        {
            InitializeComponent();
            label.Text = Name;
        }

        public float BorderWidth
        {
            get
            {
                return _borderWidth;
            }
            set
            {
                _borderWidth = value;
                Invalidate();
            }
        }

        public string Caption
        {
            get
            {
                return label.Text;
            }
            set
            {
                label.Text = value;
                label.Width = (int)(label.Font.Size*(label.Text.Length-1));
            }
        }

        public Font CaptionFont
        {
            get
            {
                return label.Font;
            }
            set
            {
                label.Font = value;
                Caption = Caption;
            }
        }

        public override Color BackColor
        {
            get
            {
                return base.BackColor;
            }
            set
            {
                label.BackColor = value;
                base.BackColor = value;
            }
        }

        public override Color ForeColor
        {
            get
            {
                return base.ForeColor;
            }
            set
            {
                label.ForeColor = value;
                base.ForeColor = value;
                Invalidate();
            }
        }

        protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
        {
            Pen pen = new Pen(ForeColor, _borderWidth);
            e.Graphics.DrawRectangle(pen, new Rectangle((int)(_borderWidth / 2), (int)((_borderWidth+label.Height) / 2), (int)(Width - _borderWidth), (int)(Height - (_borderWidth+label.Height) / 2)));
            base.OnPaint(e);
        }
    }
}
